<h3>FASP: <%= link_to sanitize(@provider.name), sanitize(@provider.base_url) %></h3>

<div class="row">
  <div class="col-md-4">
    <div class="card mb-3">
      <div class="card-header">
        <%= t ".registration" %>
      </div>
      <div class="card-body">
        <p>Requested at: <%= @provider.created_at %></p>
        <p>Status: <%= @provider.status %></p>
      </div>
    </div>
  </div>
  <div class="col-md-4">
    <div class="card mb-3">
      <div class="card-header">
        <%= t ".links" %>
      </div>
      <div class="card-body">
        <ul>
          <% if @provider.privacy_policy.any? %>
            <li><%= link_to t(".privacy_policy"), sanitize(@provider.privacy_policy.first["url"]) %></li>
          <% end %>
          <% if @provider.sign_in_url %>
            <li><%= link_to t(".sign_in"), sanitize(@provider.sign_in_url) %></li>
          <% end %>
        </ul>
      </div>
    </div>
  </div>
  <div class="col-md-4">
    <div class="card mb-3">
      <div class="card-header">
        <%= t ".contact_details" %>
      </div>
      <div class="card-body">
        <% if @provider.contact_email %>
          <p><%= t ".email" %>: <%= link_to sanitize(@provider.contact_email), "mailto:#{@provider.contact_email}" %></p>
        <% end %>
        <% if @provider.fediverse_account %>
          <p><%= t ".fediverse_account" %>: <%= sanitize(@provider.fediverse_account) %></p>
        <% end %>
      </div>
    </div>
  </div>
</div>

<div>
  <% if @provider.pending? %>
    <p><%= t ".approval_help" %>
    <p>
      <%= t ".fingerprint" %>:
      <code><%= sanitize(@provider.fingerprint) %></code>
    </p>
    <%= button_to t(".approve"), @provider, method: :patch, params: {provider: {status: "approved"}}, form: {style: "display: inline"}, class: "btn btn-success" %>
    <%= button_to t(".deny"), @provider, method: :patch, params: {provider: {status: "denied"}}, form: {style: "display: inline"}, class: "btn btn-danger" %>
  <% else %>
    <table class="table table-striped">
      <tr>
        <th><%= t ".capability" %></th>
        <th><%= t ".versions" %></th>
        <th><%= t ".enable" %></th>
        <th><%= t ".disable" %></th>
      </tr>
      <% @provider.capabilities.each do |cap| %>
        <tr>
          <td><code><%= cap["id"] %></code></td>
          <td><%= cap["version"] %></td>
          <td><%= button_to t(".enable"), @provider, method: :patch, params: {provider: {enable_capability: {id: cap["id"], version: cap["version"]}}}, class: "btn btn-success" %></td>
          <td><%= button_to t(".disable"), @provider, method: :patch, params: {provider: {disable_capability: {id: cap["id"], version: cap["version"]}}}, class: "btn btn-danger" %></td>
        </tr>
      <% end %>
    </table>
  <% end %>
</div>

<% if @provider.approved? %>
<div>
  <h3><%= t ".data_sharing" %></h3>
  <h4><%= t ".event_subscriptions" %></h4>
  <table class="table table-striped">
    <tr>
      <th><%= t ".created" %></th>
      <th><%= t ".category" %></th>
      <th><%= t ".subscription_type" %></th>
    </tr>
    <% @provider.fasp_client_event_subscriptions.each do |sub| %>
      <tr>
        <td><%= sub.created_at %></td>
        <td><%= sub.category %></td>
        <td><%= sub.subscription_type %></td>
      </tr>
    <% end %>
  </table>
  <h4><%= t ".backfill_requests" %></h4>
  <table class="table table-striped">
    <tr>
      <th><%= t ".created" %></th>
      <th><%= t ".category" %></th>
      <th><%= t ".max_count" %></th>
    </tr>
    <% @provider.fasp_client_backfill_requests.each do |req| %>
      <tr>
        <td><%= req.created_at %></td>
        <td><%= req.category %></td>
        <td><%= req.max_count %></td>
      </tr>
    <% end %>
  </table>
</div>
<% end %>
